//
//  T3FMAAnnotation.swift
//  t3_map
//
//  Created by Cunhai Li on 2024/10/22.
//

import AMapNaviKit
import UIKit

class T3FMAAnnotation: NSObject, T3FAnnotation {

    private(set) var options: T3FAnnotationOptions
    /// SDK内置的Annotation
    let realAnnotation: T3FMARealAnnotation

    lazy var annotationView: T3FAnnotationView = {
        return createAnnotationView()
    }()

    func update(options: T3FAnnotationOptions) {
        self.options = options
        /// 更新realAnnotation的坐标
        realAnnotation.coordinate = options.coordinate
        /// 更新annotationView视图元素
        annotationView.update(argvs: options.args)
    }

    init(options: T3FAnnotationOptions, realAnnotation: T3FMARealAnnotation) {
        self.options = options
        self.realAnnotation = realAnnotation
    }
}

class T3FMAAnnotationView: MAAnnotationView {

    var contentView: T3FAnnotationView?

    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {

        if let contentView = self.contentView {
            let pointInContentView = contentView.convert(point, from: self)
            return contentView.point(inside: pointInContentView, with: event)
        }
        else {
            return super.point(inside: point, with: event)
        }
    }
}

class T3FMARealAnnotation: NSObject, MAAnnotation {
    var coordinate: CLLocationCoordinate2D

    init(coordinate: CLLocationCoordinate2D) {
        self.coordinate = coordinate
    }
}
